import { http, ApiResponse } from '@/utils/http';

export interface CategoryStat {
  categoryId: number;
  categoryName: string;
  articleCount: number;
  viewCount: number;
}

export interface TagStat {
  tagId: number;
  tagName: string;
  articleCount: number;
  viewCount: number;
}

export interface TrendData {
  [date: string]: number;
}

export interface DashboardData {
  // 用户统计
  totalUsers: number;
  activeUsers: number;
  newUsersToday: number;
  newUsersThisWeek: number;
  newUsersThisMonth: number;
  
  // 文章统计
  totalArticles: number;
  publishedArticles: number;
  draftArticles: number;
  newArticlesToday: number;
  newArticlesThisWeek: number;
  newArticlesThisMonth: number;
  
  // 互动统计
  totalViews: number;
  totalLikes: number;
  totalComments: number;
  viewsThisWeek: number;
  viewsThisMonth: number;
  likesThisWeek: number;
  likesThisMonth: number;
  commentsThisWeek: number;
  commentsThisMonth: number;
  
  // 评论状态统计
  pendingComments: number;
  approvedComments: number;
  newCommentsToday: number;
  newCommentsThisWeek: number;
  
  // 通知统计
  totalNotifications: number;
  unreadNotifications: number;
  systemNotifications: number;
  
  // 分类和标签统计
  totalCategories: number;
  topCategories: CategoryStat[];
  totalTags: number;
  topTags: TagStat[];
  
  // 趋势数据
  userTrend: TrendData;
  articleTrend: TrendData;
  viewTrend: TrendData;
  commentTrend: TrendData;
}

export const getDashboardData = (startDate: string, endDate: string): Promise<ApiResponse<DashboardData>> => {
  return http.get('/api/dashboard', {
    params: {
      startDate,
      endDate,
    },
  });
};

export const dashboardApi = {
  // 获取仪表盘数据
  getDashboardData() {
    return http.get<DashboardData>('/dashboard');
  },

  // 获取趋势数据
  getTrendData(days: number = 7) {
    return http.get<DashboardData>('/dashboard/trends', { params: { days } });
  },

  // 获取热门分类
  getTopCategories(limit: number = 10) {
    return http.get<DashboardData>('/dashboard/categories/top', { params: { limit } });
  },

  // 获取热门标签
  getTopTags(limit: number = 10) {
    return http.get<DashboardData>('/dashboard/tags/top', { params: { limit } });
  },
}; 